package com.pyxis.amidrinking;

import java.util.List;

import com.pyxis.amidrinking.db.DBBehaverages;
import com.pyxis.amidrinking.entities.BehaverageCategory;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class DrinkingScreen extends Activity {

	private Context context;
	private TextView txtDrinkType;
	private List<BehaverageCategory> lstCategories;
	public int currentItem = 0;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drinking_screen);
        this.context = this;
        configureButtons();
        
        this.txtDrinkType = (TextView) this.findViewById(R.id.txtDrinkType);
        
        loadData();
    }

	private void loadData() {
		DBBehaverages.populate();
		this.lstCategories = DBBehaverages.lstCategories;
		loadCategotyItem();
	}

	private void loadCategotyItem() {
		BehaverageCategory category = this.lstCategories.get(this.currentItem);
		this.txtDrinkType.setText(category.description);
		
	}

	private void configureButtons() {
		ImageButton bevType = (ImageButton) this.findViewById(R.id.btnBevType);
        bevType.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Bundle b = new Bundle();
				
				Intent iSpec = new Intent(context, SpecificDrinkingScreen.class);
				
				b.putString("cat", lstCategories.get(currentItem).description);
				iSpec.putExtras(b);
				
				startActivity(iSpec);
			}
		});
	
        Button btnPrevious = (Button) this.findViewById(R.id.btnPreviousDrink);
        Button btnNext = (Button) this.findViewById(R.id.btnNextDrink);
	
        btnPrevious.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				currentItem--;
				if(currentItem < 0)
					currentItem = lstCategories.size()-1;
				loadCategotyItem();
			}
		});
        
        btnNext.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				currentItem++;
				if(currentItem >= lstCategories.size())
					currentItem =0;
				loadCategotyItem();
			}
		});
	
	}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_drinking_screen, menu);
        return true;
    }
}
